<html><head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"><title>CreateFile</title></head>
<body bgcolor="#EFF1F0" link="#3A3966" vlink="#000000" alink="#000000">
<font face="Verdana, sans-serif" size="2"><p align="center"><b><font size="4">CreateFile()</font></b></p>
<p><b>语法</b></p><blockquote>

Result = <font color="#3A3966"><b>CreateFile</b></font>(#File, Filename$ [, Flags])</blockquote>

</blockquote>
<b>概要</b><br><blockquote>





Create an empty file. 

 

</blockquote><p><b>参数</b></p><blockquote>
<style type="text/css">
table.parameters { border-spacing: 0px; border-style: none; border-collapse: collapse; }
table.parameters td { border-width: 1px; padding: 6px; border-style: solid; border-color: gray; vertical-align: top; font-family:Arial; font-size:10pt; }
</style>
<table width="90%" class="parameters">
<tr><td width="10%"><i>#File</i></td>
<td width="90%"> 
The number to identify the new file. <a href="../reference/purebasic_objects.html">#PB_Any</a> 可以用来自动生成这个编码. 

</td></tr>
<tr><td><i>Filename$</i></td>
<td> 
 
The filename and path to the new file. If the filename does not include a full path, it 
is interpreted relative to the <a href="../filesystem/getcurrentdirectory.html">current directory</a>. 

 

</td></tr>
<tr><td><i>Flags (可选)</i></td>
<td> 
 
It can be a combination (using the '| operand) of the following values: 
 
<pre><font face="Courier New, Courier, mono"size="2">  <font color="#924B72">#PB_File_SharedRead</font> : the opened file can be read by another process (Windows only).
  <font color="#924B72">#PB_File_SharedWrite</font>: the opened file can be write by another process (Windows only).
  <font color="#924B72">#PB_File_NoBuffering</font>: the internal PureBasic file buffering system will be disabled for this file.
                        <a href="filebufferssize.html">FileBuffersSize()</a> can not be used on this file.
</font></pre>

combined with one of the following values (the following flags affect the <a href="writestring.html">WriteString()</a>(), <a href="writestringn.html">WriteStringN()</a>, 
<a href="readstring.html">ReadString()</a>, <a href="readcharacter.html">ReadCharacter()</a> and <a href="writecharacter.html">WriteCharacter()</a> behaviour): 
 
<pre><font face="Courier New, Courier, mono"size="2">  <font color="#924B72">#PB_Ascii</font>  : all read/write string operation will use ascii if not specified otherwise (default for ASCII executable).
  <font color="#924B72">#PB_UTF8</font>   : all read/write string operation will use UTF-8 if not specified otherwise (default for Unicode executable).
  <font color="#924B72">#PB_Unicode</font>: all read/write string operation will use Unicode if not specified otherwise.
</font></pre>

</td></tr>
</table>
</blockquote><p><b>返回值</b></p><blockquote>



Returns nonzero if the file was created successfully and zero if there was an error. 
If <font color="#924B72">#PB_Any</font> was used as the #File parameter then the new generated number is returned on success. 

 

</blockquote><p><b>备注</b></p><blockquote>



If the file already exists, it will be overwritten by the new empty file. 
The <a href="../filesystem/filesize.html">FileSize()</a> function can be used to determine whether a file exists so the 
user can be prompted before overwriting a file. 
<br>
<br>
To open an existing file for reading/writing, use the <a href="openfile.html">OpenFile()</a> function. To open a file for 
reading only, use <a href="readfile.html">ReadFile()</a>. 

 

</blockquote><p><b>示例</b></p><blockquote>

<pre><font face="Courier New, Courier, mono"size="2">
  <b><font color="#3A3966">If</font></b> <font color="#3A3966">CreateFile</font>(0, "Text.txt")         <font color="#3A3966">; we create a new text file...</font>
    <b><font color="#3A3966">For</font></b> a=1 <b><font color="#3A3966">To</font></b> 10
<font color="#3A3966">      WriteStringN</font>(0, "Line "+<font color="#3A3966">Str</font>(a))  <font color="#3A3966">; we write 10 lines (each with 'end of line' character)</font>
    <b><font color="#3A3966">Next</font></b>
    <b><font color="#3A3966">For</font></b> a=1 <b><font color="#3A3966">To</font></b> 10
<font color="#3A3966">      WriteString</font>(0, "String"+<font color="#3A3966">Str</font>(a))  <font color="#3A3966">; and now we add 10 more strings on the same line (because there is no 'end of line' character)</font>
    <b><font color="#3A3966">Next</font></b>
<font color="#3A3966">    CloseFile</font>(0)                       <font color="#3A3966">; close the previously opened file and store the written data this way</font>
  <b><font color="#3A3966">Else</font></b>
<font color="#3A3966">    MessageRequester</font>("Information","may not create the file!")
  <b><font color="#3A3966">EndIf</font></b>

</font></pre>

</blockquote><p><b>参阅</b></p><blockquote>

<a href="openfile.html">OpenFile()</a>, <a href="readfile.html">ReadFile()</a>, <a href="closefile.html">CloseFile()</a> 

</Blockquote><p><b>已支持操作系统 </b><Blockquote>所有</Blockquote></p><center>&lt;- <a href=closefile.html>CloseFile()</a> - <a href="index.html">File Index</a> - <a href="eof.html">Eof()</a> -&gt;<br><br>

</body></html>